package com.xxx.video.commen.views;

import android.content.Context;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;


import com.xxx.video.R;

import butterknife.BindView;

public class CustomTipToast extends BaseToast {
    /**
     * error type
     */
    public static final int TYPE_ERROR = 1;
    /**
     * success type
     */
    public static final int TYPE_SUCCESS = 2;

    @BindView(R.id.tv_toast_tip_msg)
    TextView tvToastTipMsg;

    /**
     * Construct an empty Toast object.  You must call {@link #setView} before you
     * can call {@link #show}.
     *
     * @param context The context to use.
     */
    private CustomTipToast(Context context) {
        super(context);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initView(View view) {

    }

    /**
     * this is a make toast method
     *
     * @param context context
     * @param type    type
     * @param msg     tip msg
     * @return toast
     */
    public static CustomTipToast makeText(Context context, int type, String msg) {
        CustomTipToast customTipToast = new CustomTipToast(context);
        customTipToast.setType(type, msg);
        customTipToast.setDuration(Toast.LENGTH_SHORT);
        return customTipToast;
    }

    /**
     * set text content
     *
     * @param msg content
     */
    public void setText(int type, String msg) {
        if (null != tvToastTipMsg) {
            setType(type, msg);
        }
    }

    /**
     * set type and msg
     *
     * @param type type
     * @param msg  tip
     */
    private void setType(int type, String msg) {
        switch (type) {
            case TYPE_ERROR:
                tvToastTipMsg.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_actionbar_left_close, 0, 0);
                break;
            case TYPE_SUCCESS:
                tvToastTipMsg.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_custom_toast_right, 0, 0);
                break;
            default:
                break;
        }
        tvToastTipMsg.setText(msg);
    }

    @Override
    protected int getContentLayout() {
        return R.layout.toast_custom_tip;
    }
}
